package com.card.user;

import org.json.JSONObject;

import com.google.gson.JsonObject;
import com.xiaoao.net.json.message.JsonMessage;
import com.xiaoao.net.utils.PubFunc;
import com.xiaoao.net.utils.StringUtil;
import com.xiaoao.net.utils.json.GSONUtils;

/**
 * 用户额外信息
 * @author xiaoaogame
 *
 */
public class UserExtra extends UserDataComponent{
	private String img;
	private String nickName;
	private int sex;
	private String address;
	
	private String IdCard;
	private String realName;
	
	public void updateInfo(String wechatPlatform) {
		try {
			JSONObject json = new JSONObject(wechatPlatform);
			setImg(json.get("headimgurl").toString());
			String name = json.getString("nickname");
			setNickName(name);
			setSex(PubFunc.parseInt(json.opt("sex")));
			if(Changed()) {
				super.Context().Store();
			}
		} catch (Exception e) {
		}
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		if(!StringUtil.equals(this.img, img)) {
			this.img = img;
			SetChanged();
		}
	}
	public void setSex(int sex) {
		if(this.sex != sex) {
			this.sex = sex;
			SetChanged();
		}
	}

	public void setNickName(String nickName) {
		if(!StringUtil.equals(this.nickName, nickName)) {
			this.nickName = nickName;
			SetChanged();
		}
	}
	
	public void fillMsg(JsonMessage message) {
		message.addProperty("img", img);
		message.addProperty("nickName", nickName);
		message.addProperty("sex", sex);
		message.addProperty("address", address==null?"":address);//所在地
		message.addProperty("realNameAuth", isRealNameAuth());//新加
	}
	public void realNameAuth(String id,String name) {
		this.IdCard = id;
		this.realName = name;
		SetChanged();
	}
	public boolean isRealNameAuth() {
		return !StringUtil.NullOrEmpty(IdCard);
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
		SetChanged();
	}

	public String getNickName() {
		return nickName;
	}

	public int getSex() {
		return sex;
	}
	
}
